package manager.dao;

import manager.common.BaseDao;
import manager.pojo.Users;

import java.sql.ResultSet;

//数据访问层
public class UserDao {
    //1.将用户输入的账号和密码同时传入数据库进行校验
    //2.只讲用户输入的账号传入数据
    //根据账号和角色id查询用户
    public Users getUserByName(String userName,int roleId){
        //System.out.println(userName + "," + roleId);
        Users users=null;
        StringBuilder sql =new StringBuilder();
        sql.append("SELECT t1.* ");
        sql.append("from users t1, user_role t2 ");
        sql.append("where t1.user_id = t2.user_id and t1.username = ? and t2.role_id = ? ");
        Object[] obj ={userName,roleId};
        ResultSet rs= BaseDao.executedDQL(sql.toString(),obj);
        try {
            while(rs.next()){
                users=new Users(rs.getInt("user_id"),
                        rs.getString("username"),
                        rs.getString("password"),
                        rs.getString("uname"),
                        rs.getString("tel"),
                        rs.getString("sex"),
                        rs.getDate("bir"));
            }
        }catch(Exception e){
            e.printStackTrace();
        }

        return users;
    }


}
